package com.icewld.dus;

import android.content.Context;
import android.view.KeyEvent;
import android.view.SurfaceView;
import android.widget.Toast;

public class MonitorView extends SurfaceView {
    private Context contexts;
    private CameraDo cd;
    private int face = 0;

    public MonitorView(Context context) {
        super(context);
        contexts = context;
        cd = new CameraDo(contexts, face, this);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN){
            cd.takePicture();
        }
        else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP){
            if (face == 0){
                face = 1;
                Toast.makeText(contexts, "前", Toast.LENGTH_SHORT).show();
            }
            else {
                face = 0;
                Toast.makeText(contexts, "后", Toast.LENGTH_SHORT).show();
            }
            cd.closeACmera();
            cd = new CameraDo(contexts, face, this);
            cd.openACamera();
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        return super.onKeyUp(keyCode, event);
    }
}
